package com.gareve.twoSides.input;

import java.util.Collections;
import java.util.Iterator;
import java.util.Stack;

public class InputStatus {
	Stack<Integer> directions;
	public InputStatus(){
		directions = new Stack<Integer>();
	}	
	
	private void deleteFromStack(int key){
		Collections.reverse(directions);
		for(Iterator<Integer> it = directions.iterator();it.hasNext();){
			Integer dir = it.next();
			if(dir == key){
				it.remove();
				break;
			}	
		}
		Collections.reverse(directions);
	}
	public void pressKey(int key){directions.add(key);}
	public void releaseKey(int key){deleteFromStack(key);}
	
	public int peek(){
		if(directions.isEmpty())
			return -1;
		return directions.peek();
	}
	
	public boolean peek2(int key){
		return directions.contains(key);
	}
}